package HJ;

import java.util.*;

public class test3 {
    /**
     * 1 2
     * 2 3
     * 1 6
     * 7 8
     * 将数组升序，求数组交集，在将交集合并
     * @param args
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        List<String> inList = new ArrayList<>();
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            if (str == null || str.equals("")) {
                break;
            }
            inList.add(str);
        }
        int[][] inArray = new int[inList.size()][2];
        for (int i = 0; i < inList.size(); i++) {
            String[] strArray = inList.get(i).split(" ");
            inArray[i][0] = Integer.parseInt(strArray[0]);
            inArray[i][1] = Integer.parseInt(strArray[1]);
        }
        Arrays.sort(inArray, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0]-o2[0];
            }
        });
        int[][] mergeArray = new int[inList.size()][2];
        mergeArray[0][0] = Integer.MAX_VALUE;
        mergeArray[0][1] = Integer.MAX_VALUE;
        for (int i = 1; i < inArray.length; i++) {
            mergeArray[i][0] = Integer.MAX_VALUE;
            mergeArray[i][1] = Integer.MAX_VALUE;
            // 确定第一个数字
            if (inArray[i][0] <= inArray[i-1][1]) {
                mergeArray[i][0] = inArray[i][0];
                mergeArray[i][1] = Math.min(inArray[i-1][1], inArray[i][1]);
            } else {
                mergeArray[i-1][0] = inArray[i-1][0];
                mergeArray[i-1][1] = inArray[i-1][1];
                mergeArray[i][0] = inArray[i][0];
                mergeArray[i][1] = inArray[i][1];
            }
        }
        Arrays.sort(mergeArray, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0]-o2[0];
            }
        });
        int[][] resultArray = new int[mergeArray.length][2];
        resultArray[0][0] = Integer.MAX_VALUE;
        resultArray[0][1] = Integer.MAX_VALUE;
        for (int i = 1; i < mergeArray.length; i++) {
            resultArray[i][0] = Integer.MAX_VALUE;
            resultArray[i][1] = Integer.MAX_VALUE;
            if (mergeArray[i][0] <= mergeArray[i-1][1]) {
                resultArray[i][0] = mergeArray[i-1][0];
                resultArray[i][1] = Math.max(mergeArray[i][1], mergeArray[i-1][1]);
            } else {
                resultArray[i-1][0] = mergeArray[i-1][0];
                resultArray[i-1][1] = mergeArray[i-1][1];
                resultArray[i][0] = mergeArray[i][0];
                resultArray[i][1] = mergeArray[i][1];
            }
        }
        Arrays.sort(mergeArray, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0]-o2[0];
            }
        });
        boolean flag = true;
        for (int i = 0; i < resultArray.length; i++) {
            if(resultArray[i][0] < Integer.MAX_VALUE) {
                flag = false;
                System.out.println(resultArray[i][0] +" " +resultArray[i][1]);
            }
        }
        if (flag) {
            System.out.println("None");
        }
    }

    public static void sortArray(int[][] resultArray) {
        for (int i = 1; i < resultArray.length; i++) {
            for(int j=i; j>0; j--) {
                if (resultArray[j][0] < resultArray[j-1][0]) {
                    int temp0 = resultArray[j-1][0];
                    int temp1 = resultArray[j-1][1];
                    resultArray[j-1][0] = resultArray[j][0];
                    resultArray[j-1][1] = resultArray[j][1];
                    resultArray[j][0] = temp0;
                    resultArray[j][1] = temp1;
                }
            };
        }
    }
}
